package com.xm.xmapp.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.xm.xmapp.R;

public class SelectPhotoDialog extends Dialog {

	Activity activity;

	private OnClickPhoto l;

	public interface OnClickPhoto {
		void takePhotoFramCamera();

		void takePhotoFromSrc();
	}

	public SelectPhotoDialog(Context context, int theme) {
		super(context, theme);
	}

	public SelectPhotoDialog(Activity activity) {
		this(activity, R.style.share_Dialog);
		this.activity = activity;

	}

	public void setL(OnClickPhoto l) {
		this.l = l;
	}

	@Override
	public boolean onTouchEvent(MotionEvent event) {
		// TODO Auto-generated method stub

		return super.onTouchEvent(event);

	}

	@SuppressWarnings("deprecation")
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.dialog_selectphoto);

		findViewById(R.id.quxiao).setOnClickListener(
				new View.OnClickListener() {

					@Override
					public void onClick(View arg0) {

						dismiss();
					}
				});

		findViewById(R.id.phone).setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View arg0) {
				dismiss();
				if(l!=null)
				{
					l.takePhotoFromSrc();
				}
			}
		});

		findViewById(R.id.title).setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View arg0) {
				dismiss();
				if(l!=null)
				{
					l.takePhotoFramCamera();
				}
			}
		});

		Window window = getWindow();
		WindowManager.LayoutParams wl = window.getAttributes();
		wl.alpha = 1.0f;
		wl.gravity = Gravity.BOTTOM;
		WindowManager wm = activity.getWindowManager();
		wl.width = wm.getDefaultDisplay().getWidth();
		window.setAttributes(wl);
		setCancelable(true);
		setCanceledOnTouchOutside(true);

	}

}
